Friday, August 15, 2025

Personal Diary Management System || C Code Projects for School students

 Reference: Personal Diary Management System

Introduction

In the digital age, keeping a personal diary is easier than ever! Why not create your own Personal Diary Management System in C? This beginner-friendly C project helps students (ages 8-16) learn C programming while developing a real-world application.

In this tutorial, we’ll walk through building a simple diary system where users can add, view, search, and delete diary entries using file handling in C.


📌 Features of the Personal Diary Management System

Add Diary Entry – Save your thoughts with a date and title.
 
View Entries – Read all stored diary entries.
 
Search Functionality – Find entries by date or keywords.
 
Delete Entries – Remove all diary records.
 
Basic Authentication (Optional) – Password-protect your diary.


🛠 Technologies Used

📌 Programming Language: C
 📌 Compiler: MinGW (Code::Blocks IDE)
 📌 Data Storage: File Handling (
diary.txt)


📜 C Code Implementation

Below is the complete C code for the Personal Diary Management System:

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

 

#define FILE_NAME "diary.txt"

#define MAX_ENTRY_SIZE 500

#define PASSWORD "1234" 

 

void addEntry();

void viewEntries();

void searchEntry();

void deleteEntry();

int authenticateUser();

 

int main() {

    int choice;

    printf("\n=== Personal Diary Management System ===\n");

 

    if (!authenticateUser()) {

        printf("Incorrect Password. Exiting...\n");

        return 0;

    }

 

    do {

        printf("\n1. Add Entry\n2. View Entries\n3. Search Entry\n4. Delete Entry\n5. Exit\n");

        printf("Enter your choice: ");

        scanf("%d", &choice);

        getchar();

 

        switch (choice) {

            case 1: addEntry(); break;

            case 2: viewEntries(); break;

            case 3: searchEntry(); break;

            case 4: deleteEntry(); break;

            case 5: printf("Exiting...\n"); break;

            default: printf("Invalid choice! Try again.\n");

        }

    } while (choice != 5);

 

    return 0;

}

 

int authenticateUser() {

    char pass[10];

    printf("Enter password: ");

    scanf("%s", pass);

    return strcmp(pass, PASSWORD) == 0;

}

 

void addEntry() {

    FILE *file = fopen(FILE_NAME, "a");

    if (!file) { printf("Error opening file!\n"); return; }

 

    char date[20], title[50], content[MAX_ENTRY_SIZE];

 

    printf("Enter date (YYYY-MM-DD): ");

    fgets(date, sizeof(date), stdin);

    strtok(date, "\n");

 

    printf("Enter title: ");

    fgets(title, sizeof(title), stdin);

    strtok(title, "\n");

 

    printf("Enter your diary entry:\n");

    fgets(content, sizeof(content), stdin);

    strtok(content, "\n");

 

    fprintf(file, "[Date: %s]\nTitle: %s\nContent: %s\n-----\n", date, title, content);

    fclose(file);

    printf("Entry added successfully!\n");

}

 

void viewEntries() {

    FILE *file = fopen(FILE_NAME, "r");

    if (!file) { printf("No diary entries found!\n"); return; }

 

    char ch;

    printf("\n=== Diary Entries ===\n");

    while ((ch = fgetc(file)) != EOF) { putchar(ch); }

    fclose(file);

}

 

void searchEntry() {

    FILE *file = fopen(FILE_NAME, "r");

    if (!file) { printf("No diary entries found!\n"); return; }

 

    char keyword[50], line[MAX_ENTRY_SIZE];

    int found = 0;

 

    printf("Enter keyword to search: ");

    fgets(keyword, sizeof(keyword), stdin);

    strtok(keyword, "\n");

 

    printf("\n=== Search Results ===\n");

    while (fgets(line, sizeof(line), file)) {

        if (strstr(line, keyword)) {

            found = 1;

            printf("%s", line);

            while (fgets(line, sizeof(line), file) && strcmp(line, "-----\n") != 0) {

                printf("%s", line);

            }

            printf("\n");

        }

    }

    fclose(file);

    if (!found) { printf("No matching entries found!\n"); }

}

 

void deleteEntry() {

    printf("Are you sure you want to delete all entries? (y/n): ");

    char confirm;

    scanf(" %c", &confirm);

    if (confirm == 'y' || confirm == 'Y') {

        FILE *file = fopen(FILE_NAME, "w");

        if (file) { fclose(file); printf("All entries deleted!\n"); }

        else { printf("Error deleting entries!\n"); }

    } else { printf("Deletion canceled.\n"); }

}

 


📌 How to Run This Project in Code::Blocks

  1. Open Code::Blocks IDE.
  2. Create a New C File (diary_management.c).
  3. Copy and Paste the Above Code.
  4. Save the File.
  5. Click "Build and Run" (or Press F9).
  6. Interact with the Program via the Menu.

📁 Where Diary Entries Are Stored

📝 The diary entries are saved in a file called diary.txt.
 📌 Located in the same directory as the compiled
.exe file.

Example of diary.txt:

[Date: 2025-03-01]

Title: My First Entry

Content: Today, I learned C programming!

-----

 


💡 Why This is a Great Project for Beginners

🚀 Introduces File Handling – Learn how to read/write files in C.
 🚀 Reinforces Control Structures – Uses loops, functions, and conditionals.
 🚀 Practical Use Case – A real-world project for personal journaling.
 🚀 Enhancement Possibilities – Add GUI, encryption, or database storage.


📝 Conclusion

This Personal Diary Management System is a perfect beginner project for students and programmers learning C programming. With simple file handling, menu-driven structure, and basic authentication, this project lays the foundation for more advanced applications.

💡 Try it out, enhance it, and make it your own! 🚀

📌 Download Full Code & More C Projects Below In the eBook link! 👇

------------------------

Brief About “C Code Projects for Beginner Students (Ages 8-16)" eBook

Are you a school student aged 8 to 16 with a budding interest in programming, or perhaps looking for a hands-on way to master C language for your academic projects? Look no further! I am thrilled to announce the launch of "C Code Projects for Beginner Students," your ultimate guide to practical C programming.

 

Ready to start your coding adventure?

[Click below any links to get your copy of "C Code Projects for Beginner Students (Ages 8-16)"!]

 

eBook CCP_L01 Link:

https://play.google.com/store/books/details?id=KS54EQAAQBAJ  [Google Play Store]

https://books.google.co.in/books?id=KS54EQAAQBAJ   [Google Books]

 

Enjoy this eBook CCP_L01 on ‘C Code Projects for Beginner Students’ series and do not forget to explore other resources related to this series eBook. Thanks for visiting my blog.

 

EBOOK CCP_L01 promotion Blog Link:

https://myspacemywork2024.blogspot.com/2025/08/unlock-world-of-code-introducing-c-code.html

 

Happy Reading!

…till next post, bye-bye & take care!

No comments:

Post a Comment